# -*-* encoding:UTF-8 -*-
# author : mengy
# date   : 2018/11/22

import smtplib
from email.mime.text import MIMEText
from email.header import Header

# 第三方 SMTP 服务
mail_host = "smtp.qq.com"
mail_port = 25
mail_user = "1215012319@qq.com"
mail_pwd = "dishang0117/"

# 邮件接收者
receivers = ["mengyanyuan@outlook.com","1215012319@qq.com"]

# 三个参数：第一个为文本内容，第二个 plain 设置文本格式，第三个 utf-8 设置编码
message = MIMEText("Python 邮件发送测试","plain","utf-8")
# 发送者
message['From'] = Header("周世雄","utf-8")
# 接收者
message['To'] = Header('接收者',"utf-8")

subject = "Python SMTP 测试邮件"
message['Subject'] = Header(subject,"utf-8")

try:
    smtpObj = smtplib.SMTP()
    smtpObj.connect(mail_host,mail_port)
    smtpObj.login(mail_user,mail_pwd)
    smtpObj.sendmail(mail_user,receivers,message.as_string())
    print("邮件发送成功")
except Exception as e:
    print("发送邮件失败，原因:",e)
